package client;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;

import javax.swing.DefaultListModel;

import entry.Entry;

public class DirectoryListing extends DefaultListModel {

	private String mDirectory;

	private ArrayList<Entry> entries = new ArrayList<Entry>();

	/*
	 * Set methods.
	 */

	public void setDirectory(String dir) {
		mDirectory = dir;
	}

	/*
	 * Get methods.
	 */

	public String getDirectory() {
		return mDirectory;
	}

	public void addAll(Collection<Entry> list) {
		super.clear();

		entries.clear();
		entries.addAll(list);

		for (Entry item : list) {
			System.out.println("\t> search results: " + item.key);
			super.addElement(item.key);
		}

		this.fireContentsChanged(this, 0, entries.size());
	}

	@Override
	public Object get(int index) {
		return entries.get(index).key;
	}

	public Object getFull(int index) {
		return entries.get(index).value;
	}

	@Override
	public int size() {
		return entries.size();
	}

	/*
	 * We don't care about case for sorting.
	 */
	private static Comparator<String> mComparator = new Comparator<String>() {

		@Override
		public int compare(String a, String b) {
			return a.toLowerCase().compareTo(b.toLowerCase());
		}

	};

}
